import {Dom,http} from "../common/common";
class CaptchaConfig {
    constructor(args) {
        if (!args.bindEl) {
            throw new Error("[TAC] 必须配置 [bindEl]用于将验证码绑定到该元素上");
        }
		//绑定元素
        this.bindEl = args.bindEl;
        this.domBindEl = Dom(args.bindEl);
		//设置验证回调
		this.validCaptcha=args.validCaptcha;
		//刷新按钮回调
		this.btnRefreshFun=args.btnRefreshFun;
		//关闭按钮回调
		this.btnCloseFun=args.btnCloseFun
    }
}

function wrapConfig(config) {
    if (config instanceof CaptchaConfig) {
        return config;
    }
    return new CaptchaConfig(config);
}

function wrapStyle(style) {
    if (!style) {
        style = {}
    }

    if (!style.btnUrl) {
        // 设置默认图片
        style.btnUrl = "";
    }
    if (!style.moveTrackMaskBgColor && !style.moveTrackMaskBorderColor) {
        style.moveTrackMaskBgColor = "#89d2ff";
        style.moveTrackMaskBorderColor = "#0298f8";

    }
    return style;
}

const captchaRequestChains = {}


export {CaptchaConfig, wrapConfig, wrapStyle}
